< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03080302.xhp

(section: rnd) (bookmark: bm_id3148685)
Rnd function

Rnd 関数

Rnd Function [Runtime]
Rnd 関数 [実行時](hd_id3148685.1)

Returns a random number between 0 and 1.
0 から 1 の間の乱数を返します。(par_id3149669.2)

(/section: rnd)

Syntax:
構文:(hd_id3153897.3)

Rnd [(Expression)]
Rnd [(Expression)](par_id3150543.4)

Return value:
戻り値:(hd_id3149655.5)

Double
倍精度(par_id3154365.6)

Parameters:
パラメータ:(hd_id3154909.7)

Expression: Any numeric expression that defines how to generate random numbers.
Expression: 乱数の発生の種とする任意の数値表式。(par_id3125864.8)

Less than zero: Always returns the same random number.
ゼロより小さい数値: 常に同じ乱数系列を生成して返します。(par_id3156423.9)

Greater than zero: Returns the next random number in the sequence.
ゼロより大きい数値: 乱数系列の次の値を生成して返します。(par_id3149560.10)

Zero: Returns the random number that was last generated.
ゼロ: 前回と同じ乱数系列を生成して返します。(par_id3148648.11)

Omitted: Returns the next random number in the sequence.
省略時: 乱数系列の次の値を生成して返します。(par_id3155306.12)

If the same number is passed for each successive call to the Rnd function, the same random-number sequence is generated. This is because the Expression parameter is used as a starting point for the next number.
Rnd 関数を呼び出す際に常に同じ値を渡すと、同じ乱数系列が生成されます。これは Expression に指定するパラメータが、次の数値を生成する際に利用されるからです。(par_id3153091.13)

The Rnd function only returns values ranging from 0 to 1. To generate random integers in a given range, use the formula in the following example:
Rnd 関数で生成できるのは 0 から 1 までの数値であり、これ以外の範囲の整数値を取る乱数が必要であれば、下記の例を参考にしてください。(par_id3147318.14)

(embed text/sbasic/shared/00000003.xhp#errorcode : linkinfo)

Error Codes

エラーコード(hd_id3152869.37)

(/embed text/sbasic/shared/00000003.xhp#errorcode)

(embed text/sbasic/shared/00000003.xhp#err5 : linkinfo)

5 Invalid procedure call
5 無効なプロシージャー呼び出しです (par_id3150891.41)

(/embed text/sbasic/shared/00000003.xhp#err5)

Example:
例:(hd_id3151118.15)

Sub ExampleRandomSelect
Sub ExampleRandomSelect(par_id3145365.16)

Dim iVar As Integer
Dim iVar As Integer(par_id3147426.17)

iVar = Int((15 * Rnd) -2)
IVar = Int((15 * Rnd) -2)(par_id3150011.18)

Select Case iVar
Select Case iVar(par_id3148575.19)

Case 1 To 5
Case 1 To 5(par_id3154097.20)

Print "Number from 1 to 5"
Print "Number from 1 to 5"(par_id3147124.21)

Case 6, 7, 8
Case 6, 7, 8(par_id3155418.22)

Print "Number from 6 to 8"
Print "Number from 6 to 8"(par_id3154943.23)

Case Is > 8 And iVar < 11
Case Is > 8 And iVar < 11(par_id3145800.24)

Print "Greater than 8"
Print "Greater than 8"(par_id3151074.25)

Case Else
Case Else(par_id3154016.26)

Print "Outside range 1 to 10"
Print "Outside range 1 to 10"(par_id3155602.27)

End Select
End Select(par_id3150328.28)

end sub
end sub(par_id3154479.29)


< Prev / Next >